package dch.opera;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Log {

	public static void log(String log){
		FileWriter fw=null;
		try {
			fw=new FileWriter(new File("f:/log.txt"),true);
			fw.write(Log.getLocalDatetimeString("GMT+8")+":"+log+"\r\n");
			fw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static String getLocalDatetimeString(String local) {  
		Calendar cal = new GregorianCalendar(TimeZone.getTimeZone(local));  
		cal.setTimeInMillis(Calendar.getInstance().getTimeInMillis());  
		String date = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH);  
		String time = cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND);  
	    return date + " " + time;  
	} 
}
